package com.common.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.controller.base.BaseAjaxController;
import com.common.dto.DictionaryDTO;
import com.common.service.DictionaryService;
import com.common.util.ConstantDefine;



@Controller
@RequestMapping("/dict")
public class DictionaryController extends BaseAjaxController<DictionaryDTO>{
	
	@Autowired
	private DictionaryService dictionaryService;

	
	/**
	 * @function 根据typeCode获取字典表集合
	 * @param dictionaryDTO typeCode
	 * @return
	 * @data 2017-8-28
	 * @author zhongpeng
	 */
	@ResponseBody
	@RequestMapping("/getByDictInfo")
	public Map<String, Object> getAllDataByTypeCode(DictionaryDTO dictionaryDTO){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		dictionaryDTO.setStatus("1");
		List<DictionaryDTO> resultList = dictionaryService.select(dictionaryDTO);
		resultMap.put("resultList", resultList);
		return resultMap;
	}

	/**
	 * @function 分页条件查询   根据类型编号
	 * @param dictionaryDTO(typeCode)
	 * @return
	 * @data 2017-8-14
	 * @author zhongpeng
	 */
	@RequestMapping("/getList")
	@ResponseBody
	public Map<String, Object> getRecipeListPaging(DictionaryDTO dictionaryDTO) {
		Map<String, Object> resultMap = dictionaryService.getDictItemPaging(dictionaryDTO);
		return resultMap;
	}
	
	/**
	 * @function 查询资源分类
	 * @param dictionaryDTO
	 * @return
	 * @data 2017-9-11
	 * @author zhongpeng
	 */
	@RequestMapping("searchByTypeAndParent")
	@ResponseBody
	public Map<String, Object> selectType(DictionaryDTO dictionaryDTO){
		Map<String, Object> resultMap = dictionaryService.selectType(dictionaryDTO);
		return resultMap;
	}
	
	@RequestMapping(value=ConstantDefine.LIST_REQ)
	@ResponseBody
	public ResponseEntity<List<DictionaryDTO>> select(DictionaryDTO entity) {
	    List<DictionaryDTO> list = dictionaryService.select(entity);
	    HttpHeaders headers = new HttpHeaders();
		headers.setContentType(MediaType.APPLICATION_JSON);
		return new ResponseEntity<List<DictionaryDTO>>(list, headers, HttpStatus.OK);
	}

	/**
	 * 联动查询，查询出省市区
	 * @author chenby
	 * @date 2017-9-5
	 * @function 
	 * @param dictionaryDTO
	 * @return
	 */
	@RequestMapping("/getPCC")
	@ResponseBody
	public Map<String, Object> getPCC(DictionaryDTO dictionaryDTO) {
		Map<String, Object> resultMap=new HashMap<>();
		resultMap.put(ConstantDefine.ROWS, dictionaryService.getPCC(dictionaryDTO));
		return resultMap;
	}
	
	/**
	 * 根据type_code查询，并根据parent_code排序
	 */
	@RequestMapping(value="/selectItem")
	@ResponseBody
	public List<DictionaryDTO> selectProvence(DictionaryDTO entity){
		return dictionaryService.getDictByi(entity);
	}
	
	/**
	 * 根据type_code查询，并根据parent_code排序
	 * @author chenby
	 * @date 2017-10-27
	 * @function 
	 * @param dictionaryDTO
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/selectByTypeCode")
	public Map<String, Object> selectByTypeCode(DictionaryDTO dictionaryDTO){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		dictionaryDTO.setStatus("1");
		List<DictionaryDTO> resultList = dictionaryService.getDictByi(dictionaryDTO);
		resultMap.put("resultList", resultList);
		return resultMap;
	}
	
	/**
	 * 查询省编号中的城市
	 */
	@RequestMapping(value="/selectItem/parent")
	@ResponseBody
	public List<DictionaryDTO> selectByParent(DictionaryDTO entity){
		return dictionaryService.getDictByp(entity);
	}
	
	/**
	 * 根据id查询
	 * @author chenby
	 * @date 2017-10-10
	 * @function 
	 * @param entity
	 * @return
	 */
	@RequestMapping(value="selectById")
	@ResponseBody
	public Map<String, Object> selectById(DictionaryDTO entity){
		Map<String, Object> resultMap=new HashMap<>();
		resultMap.put("dictionaryDTO", dictionaryService.selectByKey(entity.getId()));
		return resultMap;
	}
	
	/**
	 * 根据id删除
	 * @author chenby
	 * @date 2017-10-23
	 * @function 
	 * @param entity
	 * @return
	 */
	@RequestMapping(value="deleteById")
	@ResponseBody
	public Map<String, Object> deleteById(DictionaryDTO entity){
		Map<String, Object> resultMap=new HashMap<>();
		resultMap=dictionaryService.deleteById(entity);
		return resultMap;
	}
	
	/**
	 * @author chenby
	 * @date 2017-8-30
	 * @function
	 */
	@Override
	public String init(Model model) {
		
		return null;
	}

	/**
	 * @author chenby
	 * @date 2017-8-30
	 * @function 
	 */
	@Override
	public String init(DictionaryDTO entity, Model model) {
		
		return null;
	}

	/**
	 * @author chenby
	 * @date 2017-8-30
	 * @function 
	 */
	@Override
	public Object queryByEntity(DictionaryDTO entity) {
		
		return null;
	}

	/**
	 * @author chenby
	 * @date 2017-8-30
	 * @function 
	 */
	@Override
	public ResponseEntity<Map<String, Object>> save(DictionaryDTO entity,BindingResult bindingResult) {
		
		return null;
	}

	/**
	 * @author chenby
	 * @date 2017-8-30
	 * @function 
	 */
	@Override
	public DictionaryDTO updateInit(String id) {
		
		return null;
	}

	/**
	 * @author chenby
	 * @date 2017-8-30
	 * @function 
	 */
	@Override
	public ResponseEntity<Map<String, Object>> update(DictionaryDTO entity,BindingResult bindingResult) {
		
		return null;
	}

	/**
	 * @author chenby
	 * @date 2017-8-30
	 * @function 
	 */
	@Override
	public ResponseEntity<Map<String, Object>> delete(List<String> id) {
		
		return null;
	}
	

}
